using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using OpenComposite.EII.Repository;
using OpenComposite.Repository.Properties;

namespace OpenComposite.EII.RepositoryUIs
{
	public partial class UCRepository : RepositoryItemUI
	{
		#region Initialization

		public UCRepository(IServiceProvider serviceProvider)
			: base(serviceProvider)
		{
			InitializeComponent();

			init();
		}
		private void init()
		{
			_repository = null;
		}

		#endregion

		#region Public Members

		#region Properties
		public override IRepositoryItem RepositoryItem
		{
			get
			{
				save();
				return _repository;
			}
			set
			{
				base.RepositoryItem = value;
				if ( value is Repository.RepositoryObject ) {
					_repository = (Repository.RepositoryObject)value;
					load();
				}
			}
		}

		public override string TypeText
		{
			get { return Resources.sRepsitory; }
		}

		public override string TypeDescription
		{
			get { return ""; }
		}
		#endregion

		#region Events
		#endregion

		#region Methods
		#endregion

		#endregion

		#region Private Members

		#region Variables
		private Repository.RepositoryObject _repository;
		#endregion

		#region Methods

		private void load()
		{
			if ( _repository == null )
				throw new NullReferenceException("No repository defined.");

			txtName.Text = _repository.Name;
			txtDesc.Text = _repository.Description;
		}
		private void save()
		{
			if ( _repository == null )
				_repository = new Repository.RepositoryObject();

			_repository.Reload();

			_repository.Name = txtName.Text;
			_repository.Description = txtDesc.Text;
		}
		#endregion

		private void txtName_KeyPress(object sender, KeyPressEventArgs e)
		{
		}

		#region Event Handlers
		#endregion

		#endregion

		protected override void NotifyPropertyChange(string property, object value)
		{
			if ( property == "Name" && value != null ) {
				txtName.Text = value.ToString();
			}
		}
	}
}
